package cn.wolfcode.p2p.base.domain;

import cn.wolfcode.base.BaseDomain;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;

import cn.wolfcode.p2p.base.util.JSONUtil;
import cn.wolfcode.p2p.base.util.MaskUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 真实身份认证
 *
 * @author
 * @since 2018-11-27 10:52:58
 */
@Getter
@Setter
@Accessors(chain = true)
public class RealAuth extends BaseAuditDomain {
    public static final int SEX_MALE = 0;
    public static final int SEX_FEMALE = 1;
    /**
     * 身份证号码
     */
    private String idNumber;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 性别
     */
    private int sex = SEX_MALE;

    /**
     * 出生年月
     */
    private Date bornDate;

    /**
     * 户口所在地
     */
    private String address;


    /**
     * 身份证正面图片地址
     */
    private String image1;

    /**
     * 身份证反面图片地址
     */
    private String image2;

    // 性别显示
    public String getDisplaySex() {
        return this.sex == SEX_MALE ? "男" : "女";
    }



    // 封装回显数据
    public String getJsonString() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("realName", realName);
        map.put("idNumber", idNumber);
        map.put("sex", getDisplaySex());
        map.put("bornDate", DateFormat.getInstance().format(bornDate));
        map.put("address", address);
        map.put("state", getDisplayState());
        map.put("image1", image1);
        map.put("image2", image2);
        map.put("remark", remark);
        if (applier != null) {
            map.put("applierName", applier.getUsername());
        }
        return JSONUtil.toJSONString(map);
    }

    // 获取脱敏后的真实名字
    public String getAnonymousRealName() {
        return MaskUtil.getAnonymousRealName(realName);
    }

    // 获取脱敏后的号码
    public String getAnonymousIdNumber() {
        return MaskUtil.getAnonymousIdNumber(idNumber);
    }

    // 获取脱敏后的真实号码
    public String getAnonymousAddress() {
        return MaskUtil.getAnonymousAddress(address);
    }

}